/*
 * Copyright (C) 2012, EADS France
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 */

package xowl.benchmark;

import org.apache.log4j.Level;

/**
 *
 * @author Laurent WOUTERS
 */
public class DBPedia {
    private xowl.utils.Logger logger;
    private xowl.store.Store store;
    
    public void execute() {
        init();
        load();
    }
    
    private void init() {
        logger = new xowl.utils.Logger("DBPedia", Level.DEBUG);
        store = new xowl.store.Store(logger);
    }
    
    private void load() {
        long begin = java.lang.System.currentTimeMillis();
        store.loadGZip("data/geocoordinates-fixed.nt.gz", xowl.store.OWL2Syntax.NTriples);
        long end = java.lang.System.currentTimeMillis();
        float span = ((float)(end-begin))/1000;
        java.lang.System.out.println("-- Loading complete:");
        java.lang.System.out.println(Float.toString(span) + "s");
        java.lang.System.out.println(Float.toString(getUsedMemory() / 1024 / 1024) + "MB");
        java.lang.System.gc();
        java.lang.System.out.println(Float.toString(getUsedMemory() / 1024 / 1024) + "MB");
    }
    
    private long getUsedMemory() {
        Runtime runtime = Runtime.getRuntime();
        long maxMemory = runtime.maxMemory();
        long allocatedMemory = runtime.totalMemory();
        long freeMemory = runtime.freeMemory();
        long totalFreeMemory = freeMemory + (maxMemory - allocatedMemory);
        return maxMemory - totalFreeMemory;
    }
}
